import {
  Column,
  Entity,
  JoinColumn,
  ManyToMany,
  ManyToOne,
  OneToMany,
  PrimaryGeneratedColumn,
} from 'typeorm';
import { Student } from '../../student/entities/student.entity';
import { ClassInfo } from '../../class-info/entities/class-info.entity';
import { Department } from '../../department/entities/department.entity';
import { Exclude } from 'class-transformer';
import { Course } from '../../course/entities/course.entity';

/**
 * 专业表
 */
@Entity()
export class Major {
  @PrimaryGeneratedColumn({ type: 'int', comment: '专业编码' })
  id: number;

  @Column({ comment: '专业名称', unique: true })
  name: string;

  @Column({ comment: '描述', nullable: true })
  desc: string;

  @OneToMany(() => Student, (student) => student.major, {
    nullable: false,
  })
  student: Student[];

  @OneToMany(() => Course, (course) => course.major, { onDelete: 'SET NULL' })
  course: Course[];

  @Column({ comment: '学院表id', nullable: true })
  @Exclude()
  department_id: number;
  @ManyToOne(() => Department, (department) => department.major, {
    onDelete: 'SET NULL',
    cascade: ['insert', 'update'],
  })
  @JoinColumn({
    name: 'department_id',
  })
  department: Department;
}
